cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/FigureA6.log", replace

clear all
set more off

mat Results = J(28, 10, -9)

use "RawData/GallupDataBJPS.dta", clear

// Drops Unrepresentative Series
drop if drops == "All" | regexm(drops, "Party")
// Drops Obs. w/o Gender
drop if female < 0
// Drops Obs. w/o Weights
drop if final_weight < 0
// Drops Obs. w/o Dem., Ind., or Rep.
keep if party == -1 | party == 0 | party == 1
// Drops Obs. w/o Education
drop if education < 0

// Indicator for Phone Survey
gen phone = (survey ~= 1)

// Sets the Survey Date as the Mid-Point in Field
gen middle_date = .
replace middle_date = floor((start_date + end_date) / 2)
sort middle_date
format middle_date %td

// Codes Dem. as 0, Ind. as 1/2, and Rep. as 1
gen partisan = 0 if party == -1
replace partisan = 1 if party == 1
replace partisan = .5 if party == 0

gen year = year(middle_date)  
gen yearbin = .
replace yearbin = 1 if year >= 1978 & year <= 1982
replace yearbin = 2 if year >= 1983 & year <= 1987
replace yearbin = 3 if year >= 1988 & year <= 1992
replace yearbin = 4 if year >= 1993 & year <= 1997
replace yearbin = 5 if year >= 1998 & year <= 2002
replace yearbin = 6 if year >= 2003 & year <= 2007
replace yearbin = 7 if year >= 2008 & year <= 2012
drop if missing(yearbin)

drop if age == -99 | age == -9
drop if age <= 24
gen decade_birth = floor((year - age) / 10) * 10
gen agebin = .
replace agebin = 1 if decade_birth == 1920
replace agebin = 2 if decade_birth == 1930
replace agebin = 3 if decade_birth == 1940
replace agebin = 4 if decade_birth == 1950
replace agebin = 5 if decade_birth == 1960
drop if missing(agebin)
drop if (yearbin >= 1 & yearbin <= 2) & agebin == 5

gen college = (education == 5)

// In-Person Surveys


forvalues i = 1(1)4 {
forvalues j = 1(1)4 {
gen ageXyear`j'`i'Xnc= (agebin == `j') * (yearbin == `i') * (1 - college)
gen ageXyear`j'`i'Xc = (agebin == `j') * (yearbin == `i') * college
gen ageXyear`j'`i'XncXfemale = (agebin == `j') * (yearbin == `i') * (1 - college) * female
gen ageXyear`j'`i'XcXfemale = (agebin == `j') * (yearbin == `i') * college * female
}
drop ageXyear1`i'Xnc
}

forvalues i = 3(1)4 {
forvalues j = 5(1)5 {
gen ageXyear`j'`i'Xnc= (agebin == `j') * (yearbin == `i') * (1 - college)
gen ageXyear`j'`i'Xc = (agebin == `j') * (yearbin == `i') * college
gen ageXyear`j'`i'XncXfemale = (agebin == `j') * (yearbin == `i') * (1 - college) * female
gen ageXyear`j'`i'XcXfemale = (agebin == `j') * (yearbin == `i') * college * female
}
drop ageXyear3`i'Xnc
}

areg partisan ageXyear* [pweight = final_weight] if phone == 0, robust absorb(series) 
forvalues i = 1(1)4 {
forvalues j = 1(1)4 {
mat Results[2*(`i' - 1) + 1, 2*(`j' - 1) + 1] = _b[ageXyear`j'`i'XcXfemale]
mat Results[2*(`i' - 1) + 2, 2*(`j' - 1) + 1] = -_se[ageXyear`j'`i'XcXfemale]
mat Results[2*(`i' - 1) + 15, 2*(`j' - 1) + 1] = _b[ageXyear`j'`i'XncXfemale]
mat Results[2*(`i' - 1) + 16, 2*(`j' - 1) + 1] = -_se[ageXyear`j'`i'XncXfemale]
}
}

forvalues i = 3(1)4 {
forvalues j = 5(1)5 {
mat Results[2*(`i' - 1) + 1, 2*(`j' - 1) + 1] = _b[ageXyear`j'`i'XcXfemale]
mat Results[2*(`i' - 1) + 2, 2*(`j' - 1) + 1] = -_se[ageXyear`j'`i'XcXfemale]
mat Results[2*(`i' - 1) + 15, 2*(`j' - 1) + 1] = _b[ageXyear`j'`i'XncXfemale]
mat Results[2*(`i' - 1) + 16, 2*(`j' - 1) + 1] = -_se[ageXyear`j'`i'XncXfemale]
}
}

drop ageXyear*

// Phone Surveys

forvalues i = 3(1)7 {
forvalues j = 1(1)5 {
gen ageXyear`j'`i'Xnc= (agebin == `j') * (yearbin == `i') * (1 - college)
gen ageXyear`j'`i'Xc = (agebin == `j') * (yearbin == `i') * college
gen ageXyear`j'`i'XncXfemale = (agebin == `j') * (yearbin == `i') * (1 - college) * female
gen ageXyear`j'`i'XcXfemale = (agebin == `j') * (yearbin == `i') * college * female
}
drop ageXyear1`i'Xnc
}


areg partisan ageXyear* [pweight = final_weight] if phone == 1, robust absorb(series) 
forvalues j = 1(1)5 {
forvalues i = 3(1)7 {
mat Results[2*(`i' - 1) + 1, 2*(`j' - 1) + 2] = _b[ageXyear`j'`i'XcXfemale]
mat Results[2*(`i' - 1) + 2, 2*(`j' - 1) + 2] = -_se[ageXyear`j'`i'XcXfemale]
mat Results[2*(`i' - 1) + 15, 2*(`j' - 1) + 2] = _b[ageXyear`j'`i'XncXfemale]
mat Results[2*(`i' - 1) + 16, 2*(`j' - 1) + 2] = -_se[ageXyear`j'`i'XncXfemale]
}
}

clear 
svmat Results

forvalues i = 1(1)10 {
replace Results`i' = . if Results`i' == -9
}

gen years = 1980 if _n == 1
replace years = 1985 if _n == 3
replace years = 1990 if _n == 5
replace years = 1995 if _n == 7
replace years = 2000 if _n == 9
replace years = 2005 if _n == 11
replace years = 2010 if _n == 13
replace years = 1980 if _n == 15
replace years = 1985 if _n == 17
replace years = 1990 if _n == 19
replace years = 1995 if _n == 21
replace years = 2000 if _n == 23
replace years = 2005 if _n == 25
replace years = 2010 if _n == 27

// 1920s Cohort 

twoway (line Results1 years if mod(_n, 2) == 1 & _n <= 14, lpattern(solid) lcolor(gs0)) /*
*/ (line Results2 years if mod(_n, 2) == 1 & _n <= 14, lpattern(dash) lcolor(gs0)) /*
*/ (line Results1 years if mod(_n, 2) == 1 & _n > 14, lpattern(solid) lcolor(gs12)) /* 
*/ (line Results2 years if mod(_n, 2) == 1 & _n > 14, lpattern(dash) lcolor(gs12)), /*
*/ xtitle("Survey Year") ytitle("Partisan Gender Gap") /*
*/ ylabel(-.12(.04).04) /*
*/ xlabel(1978 " " 1980 "78-82" 1985 "83-87" 1990 "88-92" /*
*/ 1995 "93-97" 2000 "98-02" 2005 "03-07" 2010 "08-12" /*
*/ 2012 " ", notick) xmtick(1980(5)2010) /*
*/ legend(label(1 "Col. Grad. (In-Person)") label(2 "College Grad. (Phone)") /*
*/ label(3 "Not Col. Grad. (In-Person)") label(4 "Not College Grad. (Phone)")) /*
*/ graphregion(fcolor(white)) ylabel(,nogrid) 

graph export "TablesFigures/FigureA6a.eps", as(eps) replace  

// 1930s Cohort 

twoway (line Results3 years if mod(_n, 2) == 1 & _n <= 14, lpattern(solid) lcolor(gs0)) /*
*/ (line Results4 years if mod(_n, 2) == 1 & _n <= 14, lpattern(dash) lcolor(gs0)) /*
*/ (line Results3 years if mod(_n, 2) == 1 & _n > 14, lpattern(solid) lcolor(gs12)) /* 
*/ (line Results4 years if mod(_n, 2) == 1 & _n > 14, lpattern(dash) lcolor(gs12)), /*
*/ xtitle("Survey Year") ytitle("Partisan Gender Gap") /*
*/ ylabel(-.12(.04).04) /*
*/ xlabel(1978 " " 1980 "78-82" 1985 "83-87" 1990 "88-92" /*
*/ 1995 "93-97" 2000 "98-02" 2005 "03-07" 2010 "08-12" /*
*/ 2012 " ", notick) xmtick(1980(5)2010) /*
*/ legend(label(1 "Col. Grad. (In-Person)") label(2 "College Grad. (Phone)") /*
*/ label(3 "Not Col. Grad. (In-Person)") label(4 "Not College Grad. (Phone)")) /*
*/ graphregion(fcolor(white)) ylabel(,nogrid) 

graph export "TablesFigures/FigureA6b.eps", as(eps) replace  

// 1940s Cohort 

twoway (line Results5 years if mod(_n, 2) == 1 & _n <= 14, lpattern(solid) lcolor(gs0)) /*
*/ (line Results6 years if mod(_n, 2) == 1 & _n <= 14, lpattern(dash) lcolor(gs0)) /*
*/ (line Results5 years if mod(_n, 2) == 1 & _n > 14, lpattern(solid) lcolor(gs12)) /* 
*/ (line Results6 years if mod(_n, 2) == 1 & _n > 14, lpattern(dash) lcolor(gs12)), /*
*/ xtitle("Survey Year") ytitle("Partisan Gender Gap") /*
*/ ylabel(-.12(.04).04) /*
*/ xlabel(1978 " " 1980 "78-82" 1985 "83-87" 1990 "88-92" /*
*/ 1995 "93-97" 2000 "98-02" 2005 "03-07" 2010 "08-12" /*
*/ 2012 " ", notick) xmtick(1980(5)2010) /*
*/ legend(label(1 "Col. Grad. (In-Person)") label(2 "College Grad. (Phone)") /*
*/ label(3 "Not Col. Grad. (In-Person)") label(4 "Not College Grad. (Phone)")) /*
*/ graphregion(fcolor(white)) ylabel(,nogrid) 

graph export "TablesFigures/FigureA6c.eps", as(eps) replace  

// 1950s Cohort 

twoway (line Results7 years if mod(_n, 2) == 1 & _n <= 14, lpattern(solid) lcolor(gs0)) /*
*/ (line Results8 years if mod(_n, 2) == 1 & _n <= 14, lpattern(dash) lcolor(gs0)) /*
*/ (line Results7 years if mod(_n, 2) == 1 & _n > 14, lpattern(solid) lcolor(gs12)) /* 
*/ (line Results8 years if mod(_n, 2) == 1 & _n > 14, lpattern(dash) lcolor(gs12)), /*
*/ xtitle("Survey Year") ytitle("Partisan Gender Gap") /*
*/ ylabel(-.12(.04).04) /*
*/ xlabel(1978 " " 1980 "78-82" 1985 "83-87" 1990 "88-92" /*
*/ 1995 "93-97" 2000 "98-02" 2005 "03-07" 2010 "08-12" /*
*/ 2012 " ", notick) xmtick(1980(5)2010) /*
*/ legend(label(1 "Col. Grad. (In-Person)") label(2 "College Grad. (Phone)") /*
*/ label(3 "Not Col. Grad. (In-Person)") label(4 "Not College Grad. (Phone)")) /*
*/ graphregion(fcolor(white)) ylabel(,nogrid) 

graph export "TablesFigures/FigureA6d.eps", as(eps) replace  

log close
